<?php 
class plus_admin 
{ 
	function admin_plus_list() 
	{ 
		global $mysql_conn,$v_file;
		$list_page = $_GET['list_page'];
		$list_num = $_GET['list_num'];
		$sousuokey = $_GET['sousuokey'];
		if (empty($list_page)) $list_page = 1;
		if (empty($list_num)) $list_num = 10;
		if ($list_page < 5) {$list_page0 = 1;} else {$list_page0 = $list_page-4;}
		if ($list_page < 5) {$list_page1 = 1;} else {$list_page1 = $list_page-3;}
		if ($list_page < 5) {$list_page2 = 2;} else {$list_page2 = $list_page-2;}
		if ($list_page < 5) {$list_page3 = 3;} else {$list_page3 = $list_page-1;}
		if ($list_page < 5) {$list_page4 = 4;} else {$list_page4 = $list_page;}
		if ($list_page < 5) {$list_page5 = 5;} else {$list_page5 = $list_page+1;}
		if ($list_page < 5) {$list_page6 = 6;} else {$list_page6 = $list_page+2;}
		if ($list_page < 5) {$list_page7 = 7;} else {$list_page7 = $list_page+3;}
		if ($list_page < 5) {$list_page8 = 8;} else {$list_page8 = $list_page+4;}
		$page_btn .= "<button type='button' class='btn btn-white' onClick='list_page_go(".$list_page0.")'><i class='fa fa-chevron-left'></i></button>";
		$page_btn .= "<button class='btn btn-white' id='list_page".$list_page1."' onClick='list_page_go(".$list_page1.")'>".$list_page1."</button>";
		$page_btn .= "<button class='btn btn-white' id='list_page".$list_page2."' onClick='list_page_go(".$list_page2.")'>".$list_page2."</button>";
		$page_btn .= "<button class='btn btn-white' id='list_page".$list_page3."' onClick='list_page_go(".$list_page3.")'>".$list_page3."</button>";
		$page_btn .= "<button class='btn btn-white' id='list_page".$list_page4."' onClick='list_page_go(".$list_page4.")'>".$list_page4."</button>";
		$page_btn .= "<button class='btn btn-white' id='list_page".$list_page5."' onClick='list_page_go(".$list_page5.")'>".$list_page5."</button>";
		$page_btn .= "<button class='btn btn-white' id='list_page".$list_page6."' onClick='list_page_go(".$list_page6.")'>".$list_page6."</button>";
		$page_btn .= "<button class='btn btn-white' id='list_page".$list_page7."' onClick='list_page_go(".$list_page7.")'>".$list_page7."</button>";
		$page_btn .= "<button type='button' class='btn btn-white' onClick='list_page_go(".$list_page8.")'><i class='fa fa-chevron-right'></i></button>";
		$list_limit = ($list_page-1)*$list_num.",".$list_num;
		if (empty($sousuokey)) {
			$sql = "SELECT * from `plus` limit ".$list_limit;
		} else {
			$sql = "SELECT * from `plus` WHERE `plus_name` = '".$sousuokey."'";
		}
		$result = mysql_query($sql,$mysql_conn);
		while(@$row=mysql_fetch_array($result)) {
			$plus_id = $row['plus_id'];
			$plus_type = $row['plus_type'];
			$plus_name = $row['plus_name'];
			$plus_access = $row['plus_access'];
			$plus_body = $row['plus_body'];
			$sql_type = "SELECT * from `plus_type` WHERE `type_id` = '".$plus_type."'";
			$result_type = mysql_query($sql_type,$mysql_conn);
			@$row_type=mysql_fetch_array($result_type);
			$plus_type_name = $row_type['type_name'];
			$pluslist .= "<tr><td>";
			$pluslist .= "    <input type='checkbox' class='i-checks' name='input[]'>";
			$pluslist .= "</td>";
			$pluslist .= "<td>".$plus_id."</td>";
			$pluslist .= "<td>".$plus_type_name."</td>";
			$pluslist .= "<td>".$plus_name."</td>";
			$pluslist .= "<td>".$plus_access."</td>";
			$pluslist .= "<td>".$plus_body."</td>";
			$pluslist .= "<td>";
			$pluslist .= "<a href='#' class='btn btn-white btn-xs' onClick='admin_plus_edit(".$plus_id.");'><i class='fa fa-edit'></i> 编辑 </a>";
			$pluslist .= "<a href='#' class='btn btn-white btn-xs' onClick='admin_plus_del(".$plus_id.");'><i class='fa fa-trash-o'></i> 删除 </a>";
			$pluslist .= "</td></tr>";
		}
		require($v_file);
	}
	function admin_plus_add() 
	{ 
		global $mysql_conn,$v_file;
		$sql = "SELECT * from `plus_type` ";
		$result = mysql_query($sql,$mysql_conn);
		while(@$row=mysql_fetch_array($result)) {
			$type_id = $row['type_id'];
			$type_name = $row['type_name'];
			$typelist .= "<option value=".$type_id.">".$type_name."</option>";
		}
		require($v_file);
	}
	function admin_plus_add_do() 
	{ 
		global $mysql_conn;
		$plus_type = $_POST['plus_type'];
		$plus_name = $_POST['plus_name'];
		$plus_access = $_POST['plus_access'];
		$plus_body = $_POST['plus_body'];
		$sql = "SELECT * from `plus` WHERE `plus_access` = '".$plus_access."'";
		$result = mysql_query($sql,$mysql_conn);
		@$row = mysql_fetch_array($result);
		if (empty($row)) {
			$sql="INSERT INTO plus (plus_id, plus_type, plus_name, plus_access, plus_body) VALUES (NULL,'$plus_type','$plus_name','$plus_access','$plus_body')";
			$result = mysql_query($sql,$mysql_conn);
			@$row = mysql_fetch_array($result);
			echo "2";//应用添加成功
		} else {
			echo  "1";//应用名已存在
		}
	}
	function admin_plus_edit() 
	{ 
		global $mysql_conn,$v_file;
		$plus_id = $_GET['plus_id'];
		$sql = "SELECT * from `plus` WHERE `plus_id` = '".$plus_id."'";
		$result = mysql_query($sql,$mysql_conn);
		@$row = mysql_fetch_array($result);
		$plus_type = $row['plus_type'];
		$plus_name = $row['plus_name'];
		$plus_access = $row['plus_access'];
		$plus_body = $row['plus_body'];
		$sql = "SELECT * from `plus_type` ";
		$result = mysql_query($sql,$mysql_conn);
		while(@$row=mysql_fetch_array($result)) {
			$type_id = $row['type_id'];
			$type_name = $row['type_name'];
			if ($type_id == $plus_type) {
				$typelist .= "<option value=".$type_id." selected>".$type_name."</option>";
			} else {
				$typelist .= "<option value=".$type_id.">".$type_name."</option>";
			}
		}
		require($v_file);
	}
	function admin_plus_edit_do() 
	{ 
		global $mysql_conn;
		$plus_id = $_POST['plus_id'];
		$plus_type = $_POST['plus_type'];
		$plus_name = $_POST['plus_name'];
		$plus_access = $_POST['plus_access'];
		$plus_body = $_POST['plus_body'];
		$sql = "UPDATE `plus` SET `plus_type` = '".$plus_type."', `plus_name` = '".$plus_name."', `plus_access` = '".$plus_access."', `plus_body` = '".$plus_body."' WHERE `plus_id` ='".$plus_id."';";
		$result = mysql_query($sql,$mysql_conn);
		@$row = mysql_fetch_array($result);
		echo "2";
	}
	function admin_plus_del_do() 
	{ 
		global $mysql_conn;
		$plus_id = $_POST['plus_id'];
		$sql = "DELETE from `plus` WHERE `plus_id` = '".$plus_id."'";
		$result = mysql_query($sql,$mysql_conn);
		@$row = mysql_fetch_array($result);
		echo "2";
	}
} 
/* End of file democontroller.php */ 